package org.study.security.utils;

import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;
import org.study.base.utils.MD5;

/**
 * @program: securityparent
 * @description: security encoder
 * @author: lishuang
 * @create: 2021-12-03 15:51
 **/
@Component
public class DefaultPasswordEncoder implements PasswordEncoder {
    public DefaultPasswordEncoder() {
        this(-1);
    }

    public DefaultPasswordEncoder(int length) {

    }

    /**
     * 进行md5加密
     * @param charSequence
     * @return
     */
    @Override
    public String encode(CharSequence charSequence) {
        return MD5.encrypt(charSequence.toString());
    }

    /**
     * 密码校验
     *
     * @param charSequence  输入的密码
     * @param encodePassword  加密的
     * @return
     */
    @Override
    public boolean matches(CharSequence charSequence, String encodePassword) {

        return encodePassword.equals(MD5.encrypt(charSequence.toString()));
    }
}
